//package phase4Specification.testing;
//
//import java.util.*;
//
//import dbPhase.hypeerweb.Node;
//import dbPhase.hypeerweb.Parameters;
//import dbPhase.hypeerweb.Visitor;
//import dbPhase.hypeerweb.WebId;
//
//public abstract class SendVisitorzz
//implements Visitor
//{
//public SendVisitorzz() {
//}
//
///**
// * The visit method for the send visitor.
// * 
// * @param node the node being visited.
// * @param parameters needed for this visit operation
// * 
// * @pre node &ne null AND parameters &ne null AND
// *      parameters.contains(TARGET_KEY) AND parameters.get(TARGET_KEY) &ne; null AND paramenters.get(TARGET_KEY) instanceof Integer
// * @post this = target &rArr; targetOperation(node, parameters).POST_CONDITION AND
// *       this !&ne; target &rArr; intermediateOperation(node,parameters).POST_CONDITION AND findCloserNode(node, target) &ne; null AND
// *           findCloserNode(node,target).accept(this, parameters).POST_CONDITION
// * 
// */
//public void visit(Node node, Parameters parameters) {
//    int target = (Integer) parameters.get(TARGET_KEY);
//    if (target == node.getWebId().getValue()) {
//        targetOperation(node, parameters);
//    } else {
//        intermediateOperation(node, parameters);
//        Node nextNode = findCloserNode(node, target);
//        nextNode.accept(this, parameters);
//    }
//}
//
//protected abstract void targetOperation(Node node, Parameters parameters);
//
//protected void intermediateOperation(Node node, Parameters parameters) {
//}
//
//@SuppressWarnings("unchecked")
//private Node findCloserNode(Node node, int target) {
//    Node resultNode = null;
//    if (node.getWebId().getValue() != target) {
//        WebId targetId = new WebId(target);
//        CompoundResult compoundResult = node.getConnectionsContainer().findCloserNodes(node, targetId);
//        HashSet<Node> nodes = (HashSet<Node>) compoundResult.get("nodes");
//
//        resultNode = randomlySelectMemberFrom(nodes);
//    }
//
//    return resultNode;
//}
//
//private Node randomlySelectMemberFrom(HashSet<Node> set) {
//    int index = random.nextInt(set.size());
//    Iterator<Node> iter = set.iterator();
//    Node result = null;
//    int i = 0;
//    do {
//        result = iter.next();
//        i++;
//    } while (i < index);
//    return result;
//}
//
//private static final Random random = new Random();
//public static final String TARGET_KEY = "target";
//}